package com.mars.common;

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class test {
    public static void main(String[] args) {
    String a="<a href=test.html><img src=http://www.123.com/hello.gif border=0 width=100 height=200></a>,<a href=test.html><img src=http://www.123.com/hello.png border=0 width=100 height=200></a>";
    String a1="![Description]( http://www.123.com/hello.png)9999,666![Description]( http://www.123.com/hello.png)9999,666\"";
        System.out.println("imageSrc==========");
        List<String> imgStr = getImgStr(a1);
        System.out.println(imgStr);

    }


    public static List<String> getImgStr(String htmlStr) {
        List<String> list = new ArrayList<>();
        String img = "";
        Pattern p_image;
        Matcher m_image;
        // String regEx_img = "<img.*src=(.*?)[^>]*?>"; //图片链接地址
        String regEx_img = "<img.*src\\s*=\\s*(.*?)[^>]*?>";
        System.out.println(regEx_img);

        String regEx_img2 = "'/!\\\\[.*\\\\]\\\\((.+)\\\\)/'";
        p_image = Pattern.compile(regEx_img2, Pattern.CASE_INSENSITIVE);
        m_image = p_image.matcher(htmlStr);
        while (m_image.find()) {
            // 得到<img />数据
            img = m_image.group();
            // 匹配<img>中的src数据
            Matcher m = Pattern.compile("'/!\\\\[.*\\\\]\\\\((.+)\\\\)/'").matcher(img);
            while (m.find()) {
                list.add(m.group(1));
            }
        }
        return list;
    }


}